package com.cn.shchuangge.ui.activity;

import com.cn.shchuangge.ui.fragment.BagFragment;
import com.cn.shchuangge.ui.fragment.BeasicFragment;
import com.cn.shchuangge.ui.fragment.HomeFragment;
import com.cn.shchuangge.ui.fragment.MeFragment;
import com.cn.shchuangge.ui.fragment.ShoppingFragment;

/**
 * Created by 赵航 on 2017/6/18.
 */

public class FrogmentFactory {
        //单例工厂模式

    private static HomeFragment homeFragment;
    private static ShoppingFragment shoppingFragment;
    private static BagFragment bagFragment;
    private static MeFragment meFragment;

    public static BeasicFragment getFragment(int position){
        switch (position){

            case 0:
                if (homeFragment==null){
                homeFragment = new HomeFragment();
                }
                return homeFragment;
            case 1:
                if (shoppingFragment==null){
                    shoppingFragment = new ShoppingFragment();
                }

                return shoppingFragment;
            case 2:
                if (bagFragment==null){
                    bagFragment = new BagFragment();
                }

                return bagFragment;
            case 3:
                if (meFragment==null){
                meFragment = new MeFragment();
                }
                return meFragment;
        }

        return null;

    }
}
